package com.cq.hd.merchant.controller;

import com.cq.hd.common.entity.DataVo;
import com.cq.hd.common.entity.hf.HfUploadVo;
import com.cq.hd.common.enums.biz.*;
import com.cq.hd.common.response.ResultGenerator;
import com.cq.hd.merchant.biz.UploadBiz;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.*;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/common")
@Api(tags = "公共相关接口")
public class CommonController {

    @Autowired
    private UploadBiz uploadBiz;

    @ApiOperation(value = "上传图片")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "上传图片用途:0-其他，1-用户/商户/商家相关，2-活动，3-商品，4-反馈，5-文章", paramType = "path", dataType = "Integer")
    })
    @PostMapping("/upload/{type}")
    public Object upload(MultipartFile file, @PathVariable("type") Integer type, HttpServletRequest request) {
        return ResultGenerator.success(uploadBiz.upload(file, type, request));
    }

    @ApiOperation(value = "上传hf图片")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "汇付图片类型：F07-营业执照，F03-法人身份证国徽面，F02-法人身份证人像面，F08-开户许可证，F13-结算卡/银行卡正面，" +
                    " F56-结算人/持卡人身份证国徽面，F55-结算人/持卡人身份证人像面，F22-线下经营-门头照，F24-线下经营-内景照，F105-线下经营-收银台，F15-授权委托书，F301-增值电信业务经营许可证，" +
                    " F31-法人港澳台通行证正面，F506-外国护照正面，F511-外国人居留证，F512-港澳台居住证", paramType = "path", dataType = "Integer")
    })
    @ApiResponse(response = HfUploadVo.class, code = 200, message = "接口返回对象参数")
    @PostMapping("/hfUpload/{type}")
    public Object hfUpload(MultipartFile file, @PathVariable("type") String type, HttpServletRequest request) {
        return ResultGenerator.success(uploadBiz.hfUpload(file, type, request));
    }

//    @ApiOperation(value = "商家类型列表")
//    @GetMapping(value = "/listBusinessType")
//    public Object listBusinessType() {
//        List<DataVo> dataVos = new ArrayList<>();
//        Map<Integer, String> map = Arrays.stream(BusinessTypeEnum.values()).collect(Collectors.toMap(BusinessTypeEnum::getValue, BusinessTypeEnum::getName));
//        for (Integer code : map.keySet()) {
//            DataVo dataVo = new DataVo();
//            dataVo.setCode(code);
//            dataVo.setName(map.get(code));
//            dataVos.add(dataVo);
//        }
//
//        return ResultGenerator.success(dataVos);
//    }
//
//    @ApiOperation(value = "商户类型列表")
//    @GetMapping(value = "/listMerchantType")
//    public Object listMerchantType() {
//        List<DataVo> dataVos = new ArrayList<>();
//        Map<Integer, String> map = Arrays.stream(MerchantTypeEnum.values()).collect(Collectors.toMap(MerchantTypeEnum::getValue, MerchantTypeEnum::getName));
//        for (Integer code : map.keySet()) {
//            DataVo dataVo = new DataVo();
//            dataVo.setCode(code);
//            dataVo.setName(map.get(code));
//            dataVos.add(dataVo);
//        }
//
//        return ResultGenerator.success(dataVos);
//    }

    @ApiOperation(value = "公司类型列表")
    @GetMapping(value = "/listCompanyType")
    public Object listCompanyTypeEnum() {
        List<DataVo> dataVos = new ArrayList<>();
        Map<Integer, String> map = Arrays.stream(CompanyTypeEnum.values()).collect(Collectors.toMap(CompanyTypeEnum::getValue, CompanyTypeEnum::getName));
        for (Integer code : map.keySet()) {
            DataVo dataVo = new DataVo();
            dataVo.setCode(code);
            dataVo.setName(map.get(code));
            dataVos.add(dataVo);
        }

        return ResultGenerator.success(dataVos);
    }

    @ApiOperation(value = "自然人证件类型列表")
    @GetMapping(value = "/listCertType")
    public Object listCertTypeEnum() {
        List<Map<String, String>> dataVos = new ArrayList<>();
        Map<String, String> map = Arrays.stream(CertTypeEnum.values()).collect(Collectors.toMap(CertTypeEnum::getValue, CertTypeEnum::getName));
        for (String code : map.keySet()) {
            Map<String, String> subMap = new HashMap<>();
            subMap.put("code", code);
            subMap.put("name", map.get(code));
            dataVos.add(subMap);
        }

        return ResultGenerator.success(dataVos);
    }

    @ApiOperation(value = "结算账户类型列表")
    @GetMapping(value = "/listCardType")
    public Object listCardType() {
        List<DataVo> dataVos = new ArrayList<>();
        Map<Integer, String> map = Arrays.stream(CardTypeEnum.values()).collect(Collectors.toMap(CardTypeEnum::getValue, CardTypeEnum::getName));
        for (Integer code : map.keySet()) {
            DataVo dataVo = new DataVo();
            dataVo.setCode(code);
            dataVo.setName(map.get(code));
            dataVos.add(dataVo);
        }

        return ResultGenerator.success(dataVos);
    }

    @ApiOperation(value = "证件有效期类型列表")
    @GetMapping(value = "/listCertValidityType")
    public Object listCertValidityType() {
        List<DataVo> dataVos = new ArrayList<>();
        Map<Integer, String> map = Arrays.stream(CertValidityTypeEnum.values()).collect(Collectors.toMap(CertValidityTypeEnum::getValue, CertValidityTypeEnum::getName));
        for (Integer code : map.keySet()) {
            DataVo dataVo = new DataVo();
            dataVo.setCode(code);
            dataVo.setName(map.get(code));
            dataVos.add(dataVo);
        }

        return ResultGenerator.success(dataVos);
    }

    @ApiOperation(value = "银行编号列表")
    @GetMapping(value = "/listBank")
    public Object listBank() {
        List<Map<String, String>> dataVos = new ArrayList<>();
        Map<String, String> map = Arrays.stream(HfBankIdEnum.values()).collect(Collectors.toMap(HfBankIdEnum::getValue, HfBankIdEnum::getName));
        for (String code : map.keySet()) {
            Map<String, String> subMap = new HashMap<>();
            subMap.put("code", code);
            subMap.put("name", map.get(code));
            dataVos.add(subMap);
        }

        return ResultGenerator.success(dataVos);
    }



}
